<html>
<head>
<script>
function print(message)
{
    var block = document.createElement("div");
    block.appendChild(document.createTextNode(message));
    block.appendChild(document.createElement("br"));
    document.getElementById("console").appendChild(block);
}

function printProperties(object)
{
    var array = new Array;
    for (const property of Object.getOwnPropertyNames(object)) {
        if (property == "prototype") continue;
        array.push(property);
    }
    array.sort();
    for (const property of array) {
        print(property + ": {" + object[property] + "}");
    }
}

function test() {
    if (window.testRunner)  
        testRunner.dumpAsText();

    print("Properties of RegExp at startup:");
    printProperties(RegExp);
    
    var r = /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/;
    var matchingString = "<1234567890>";
    var unmatchingString = "XXX";

    var dummyRegExp = new RegExp();
    var dummyString = "";
    
    print("");
    r.exec(matchingString);
    print("Properties of RegExp after " + r + ".exec(" + matchingString + "):");
    printProperties(RegExp);

    print("");
    print("RegExp.$0 " + (RegExp.$0 ? "exists" : "does not exist"));
    print("RegExp.$10 " + (RegExp.$10 ? "exists" : "does not exist"));
    print("RegExp " + (r.test() ? "uses" : "doesn't use") + " RegExp.input");
    
    RegExp.input = Number();
    print("RegExp.input " + (typeof RegExp.input == typeof String() ? "coerces" : "doesn't coerce") + " values to strings");

    print("");
    r.exec(unmatchingString);
    print("Properties of RegExp after " + r + ".exec(" + unmatchingString + "):");
    printProperties(RegExp);

    print("");
    print("---------- [Cleared RegExp values] ----------");
    dummyRegExp.exec(dummyString);
    if (RegExp.lastMatch != "")
        print("Clear failed");

    matchingString.search(r);
    print("Properties of RegExp after " + matchingString + ".search(" + r + "):");
    printProperties(RegExp);

    print("");
    print("---------- [Cleared RegExp values] ----------");
    dummyRegExp.exec(dummyString);

    matchingString.replace(r);
    print("Properties of RegExp after " + matchingString + ".replace(" + r + "):");
    printProperties(RegExp);
}
</script>
</head>
<body onload="test();">
<p>
This test checks our implementation of the special RegExp member variables.
</p>
<hr>
<div id='console'/ style="font-family: courier; font-size: 12">
</body>
</html>
